﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace CoreProject.Model;

public partial class EFDbContext : DbContext
{
    public EFDbContext()
    {
    }

    public EFDbContext(DbContextOptions<EFDbContext> options)
        : base(options)
    {
    }

    public virtual DbSet<Authority> Authorities { get; set; }

    public virtual DbSet<Department> Departments { get; set; }

    public virtual DbSet<Good> Goods { get; set; }

    public virtual DbSet<GoodsPropertyKey> GoodsPropertyKeys { get; set; }

    public virtual DbSet<GoodsPropertyValue> GoodsPropertyValues { get; set; }

    public virtual DbSet<GoodsSpecKey> GoodsSpecKeys { get; set; }

    public virtual DbSet<GoodsSpecValue> GoodsSpecValues { get; set; }

    public virtual DbSet<GoodsType> GoodsTypes { get; set; }

    public virtual DbSet<HjqOrder> HjqOrders { get; set; }

    public virtual DbSet<HjqOrderDetail> HjqOrderDetails { get; set; }

    public virtual DbSet<HjqSalesReport> HjqSalesReports { get; set; }

    public virtual DbSet<HjqStoreInfo> HjqStoreInfos { get; set; }

    public virtual DbSet<Image> Images { get; set; }

    public virtual DbSet<Menu> Menus { get; set; }

    public virtual DbSet<Message> Messages { get; set; }

    public virtual DbSet<Pder> Pders { get; set; }

    public virtual DbSet<Pderxq> Pderxqs { get; set; }

    public virtual DbSet<Role> Roles { get; set; }

    public virtual DbSet<User> Users { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseSqlServer("Name=ConnectionStrings:DefaultConnection");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Authority>(entity =>
        {
            entity.HasKey(e => e.AuthId);

            entity.ToTable("Authority");

            entity.Property(e => e.AuthId).HasColumnName("authID");
            entity.Property(e => e.LastTime)
                .HasColumnType("smalldatetime")
                .HasColumnName("lastTime");
            entity.Property(e => e.MenuId).HasColumnName("menuID");
            entity.Property(e => e.RoleId).HasColumnName("roleID");
            entity.Property(e => e.Sort).HasColumnName("sort");

            entity.HasOne(d => d.Menu).WithMany(p => p.Authorities)
                .HasForeignKey(d => d.MenuId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Authority_Menus");

            entity.HasOne(d => d.Role).WithMany(p => p.Authorities)
                .HasForeignKey(d => d.RoleId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Authority_Roles");
        });

        modelBuilder.Entity<Department>(entity =>
        {
            entity.HasKey(e => e.DeptId);

            entity.ToTable("Department");

            entity.Property(e => e.DeptId).HasColumnName("deptID");
            entity.Property(e => e.DeptName)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("deptName");
            entity.Property(e => e.LastTime)
                .HasColumnType("smalldatetime")
                .HasColumnName("lastTime");
            entity.Property(e => e.Remark)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("remark");
            entity.Property(e => e.Type).HasColumnName("type");
        });

        modelBuilder.Entity<Good>(entity =>
        {
            entity.HasKey(e => e.GId).HasName("PK_dbo.Goods");

            entity.Property(e => e.GId).HasColumnName("gId");
            entity.Property(e => e.Content)
                .HasMaxLength(500)
                .IsUnicode(false)
                .HasColumnName("content");
            entity.Property(e => e.GtId).HasColumnName("gtId");
            entity.Property(e => e.Images)
                .HasMaxLength(200)
                .IsUnicode(false)
                .HasColumnName("images");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("name");
            entity.Property(e => e.OnSale).HasColumnName("on_sale");
            entity.Property(e => e.Price)
                .HasColumnType("smallmoney")
                .HasColumnName("price");
            entity.Property(e => e.Sales).HasColumnName("sales");
            entity.Property(e => e.Sort).HasColumnName("sort");
            entity.Property(e => e.Unit)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("unit");
            entity.Property(e => e.UseProperty).HasColumnName("use_property");
            entity.Property(e => e.UseSpec).HasColumnName("use_spec");

            entity.HasOne(d => d.Gt).WithMany(p => p.Goods)
                .HasForeignKey(d => d.GtId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Goods_GoodsType");
        });

        modelBuilder.Entity<GoodsPropertyKey>(entity =>
        {
            entity.HasKey(e => e.GpkId).HasName("PK_dbo.GoodsPropertyKey");

            entity.ToTable("GoodsPropertyKey");

            entity.Property(e => e.GpkId).HasColumnName("gpkId");
            entity.Property(e => e.GId).HasColumnName("gId");
            entity.Property(e => e.Gskid).HasColumnName("gskid");

            entity.HasOne(d => d.GIdNavigation).WithMany(p => p.GoodsPropertyKeys)
                .HasForeignKey(d => d.GId)
                .HasConstraintName("FK_GoodsPropertyKey_Goods");

            entity.HasOne(d => d.Gsk).WithMany(p => p.GoodsPropertyKeys)
                .HasForeignKey(d => d.Gskid)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_GoodsPropertyKey_GoodsSpecKey");
        });

        modelBuilder.Entity<GoodsPropertyValue>(entity =>
        {
            entity.HasKey(e => e.GpvId).HasName("PK_dbo.GoodsPropertyValue");

            entity.ToTable("GoodsPropertyValue");

            entity.Property(e => e.GpvId).HasColumnName("gpvId");
            entity.Property(e => e.GpkId).HasColumnName("gpkId");
            entity.Property(e => e.GsvId).HasColumnName("gsvId");
            entity.Property(e => e.IsDefault).HasColumnName("is_default");

            entity.HasOne(d => d.Gpk).WithMany(p => p.GoodsPropertyValues)
                .HasForeignKey(d => d.GpkId)
                .HasConstraintName("FK_GoodsPropertyValue_GoodsPropertyKey");

            entity.HasOne(d => d.Gsv).WithMany(p => p.GoodsPropertyValues)
                .HasForeignKey(d => d.GsvId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_GoodsPropertyValue_GoodsSpecValue");
        });

        modelBuilder.Entity<GoodsSpecKey>(entity =>
        {
            entity.HasKey(e => e.GskId).HasName("PK_dbo.GoodsSpecKey");

            entity.ToTable("GoodsSpecKey");

            entity.Property(e => e.GskId).HasColumnName("gskId");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("name");
        });

        modelBuilder.Entity<GoodsSpecValue>(entity =>
        {
            entity.HasKey(e => e.GsvId).HasName("PK_dbo.GoodsSpecValue");

            entity.ToTable("GoodsSpecValue");

            entity.Property(e => e.GsvId).HasColumnName("gsvId");
            entity.Property(e => e.Code)
                .HasMaxLength(32)
                .IsUnicode(false)
                .HasColumnName("code");
            entity.Property(e => e.GskId).HasColumnName("gskId");
            entity.Property(e => e.Value)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("value");

            entity.HasOne(d => d.Gsk).WithMany(p => p.GoodsSpecValues)
                .HasForeignKey(d => d.GskId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_GoodsSpecValue_GoodsSpecKey");
        });

        modelBuilder.Entity<GoodsType>(entity =>
        {
            entity.HasKey(e => e.GtId).HasName("PK_dbo.GoodsType");

            entity.ToTable("GoodsType");

            entity.Property(e => e.GtId).HasColumnName("gtId");
            entity.Property(e => e.Icon)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("icon");
            entity.Property(e => e.IsShowBackstage).HasColumnName("is_show_backstage");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("name");
            entity.Property(e => e.Sort).HasColumnName("sort");
        });

        modelBuilder.Entity<HjqOrder>(entity =>
        {
            entity.HasKey(e => e.OrderId).HasName("PK__HJQ_orde__46596229658B76DA");

            entity.ToTable("HJQ_order");

            entity.Property(e => e.OrderId)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("order_id");
            entity.Property(e => e.CreatedAt)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("created_at");
            entity.Property(e => e.OrderStatus).HasColumnName("order_status");
            entity.Property(e => e.OrderTime)
                .HasColumnType("datetime")
                .HasColumnName("order_time");
            entity.Property(e => e.PaymentMethod)
                .HasMaxLength(30)
                .IsUnicode(false)
                .HasColumnName("payment_method");
            entity.Property(e => e.RecipientName)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("recipient_name");
            entity.Property(e => e.RecipientPhone)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("recipient_phone");
            entity.Property(e => e.ShippingAddress)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasColumnName("shipping_address");
            entity.Property(e => e.TotalAmount)
                .HasColumnType("decimal(10, 2)")
                .HasColumnName("total_amount");
            entity.Property(e => e.UpdatedAt)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime")
                .HasColumnName("updated_at");
            entity.Property(e => e.UserId).HasColumnName("userID");

            entity.HasOne(d => d.User).WithMany(p => p.HjqOrders)
                .HasForeignKey(d => d.UserId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_HJQ_order_Users");
        });

        modelBuilder.Entity<HjqOrderDetail>(entity =>
        {
            entity.HasKey(e => e.DetailId).HasName("PK__HJQ_orde__38E9A2246E22FB05");

            entity.ToTable("HJQ_order_details");

            entity.Property(e => e.DetailId)
                .ValueGeneratedNever()
                .HasColumnName("detail_id");
            entity.Property(e => e.OrderId)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("order_id");
            entity.Property(e => e.ProductCategory)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("product_category");
            entity.Property(e => e.ProductId).HasColumnName("product_id");
            entity.Property(e => e.ProductName)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("product_name");
            entity.Property(e => e.ProductSpec)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("product_spec");
            entity.Property(e => e.Quantity).HasColumnName("quantity");
            entity.Property(e => e.TotalPrice)
                .HasColumnType("decimal(10, 2)")
                .HasColumnName("total_price");
            entity.Property(e => e.UnitPrice)
                .HasColumnType("decimal(10, 2)")
                .HasColumnName("unit_price");

            entity.HasOne(d => d.Order).WithMany(p => p.HjqOrderDetails)
                .HasForeignKey(d => d.OrderId)
                .HasConstraintName("FK__HJQ_order__order__15A53433");

            entity.HasOne(d => d.Product).WithMany(p => p.HjqOrderDetails)
                .HasForeignKey(d => d.ProductId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK__HJQ_order__produ__14B10FFA");
        });

        modelBuilder.Entity<HjqSalesReport>(entity =>
        {
            entity.HasKey(e => e.SalesId).HasName("PK__HJQ_sale__C952FB12EBAFC180");

            entity.ToTable("HJQ_sales_report");

            entity.Property(e => e.SalesId).HasColumnName("SalesID");
            entity.Property(e => e.CreateTime)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime");
            entity.Property(e => e.Operator)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.OrderType)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasDefaultValue("Offline");
            entity.Property(e => e.ProductName)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.SalesAmount)
                .HasComputedColumnSql("([UnitPrice]*[Quantity])", false)
                .HasColumnType("decimal(16, 2)");
            entity.Property(e => e.Specification)
                .HasMaxLength(20)
                .IsUnicode(false);
            entity.Property(e => e.StoreId).HasColumnName("StoreID");
            entity.Property(e => e.UnitPrice).HasColumnType("decimal(5, 2)");

            entity.HasOne(d => d.Store).WithMany(p => p.HjqSalesReports)
                .HasForeignKey(d => d.StoreId)
                .HasConstraintName("FK__HJQ_sales__Store__5F492382");
        });

        modelBuilder.Entity<HjqStoreInfo>(entity =>
        {
            entity.HasKey(e => e.AddressId).HasName("PK__HJQ_stor__091C2A1B077F7ADD");

            entity.ToTable("HJQ_store_info");

            entity.Property(e => e.AddressId).HasColumnName("AddressID");
            entity.Property(e => e.Dianpumj)
                .HasColumnType("decimal(5, 2)")
                .HasColumnName("dianpumj");
            entity.Property(e => e.Email)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("email");
            entity.Property(e => e.Fuzer)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("fuzer");
            entity.Property(e => e.Jingyingfw)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("jingyingfw");
            entity.Property(e => e.KefuPhone)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("kefuPhone");
            entity.Property(e => e.Liansuo).HasColumnName("liansuo");
            entity.Property(e => e.Phone)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("phone");
            entity.Property(e => e.Region)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("region");
            entity.Property(e => e.ShopAddress)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("shopAddress");
            entity.Property(e => e.ShopDate).HasColumnName("shopDate");
            entity.Property(e => e.ShopName)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("shopName");
            entity.Property(e => e.WangAddress)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("wangAddress");
            entity.Property(e => e.YingyeTime)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("yingyeTime");
        });

        modelBuilder.Entity<Image>(entity =>
        {
            entity.HasKey(e => e.ImgId);

            entity.Property(e => e.ImgId).HasColumnName("imgID");
            entity.Property(e => e.Extension)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasColumnName("extension");
            entity.Property(e => e.LastTime)
                .HasColumnType("smalldatetime")
                .HasColumnName("lastTime");
            entity.Property(e => e.Modular).HasColumnName("modular");
            entity.Property(e => e.Path)
                .HasMaxLength(200)
                .IsUnicode(false)
                .HasColumnName("path");
            entity.Property(e => e.Size).HasColumnName("size");
            entity.Property(e => e.Title)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("title");
        });

        modelBuilder.Entity<Menu>(entity =>
        {
            entity.Property(e => e.MenuId).HasColumnName("menuID");
            entity.Property(e => e.Icon)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("icon");
            entity.Property(e => e.LastTime)
                .HasColumnType("smalldatetime")
                .HasColumnName("lastTime");
            entity.Property(e => e.MenuName)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("menuName");
            entity.Property(e => e.ParentId).HasColumnName("parentID");
            entity.Property(e => e.Url)
                .HasMaxLength(200)
                .IsUnicode(false)
                .HasColumnName("url");
        });

        modelBuilder.Entity<Message>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__Message__3214EC07BA0E0A87");

            entity.ToTable("Message");

            entity.Property(e => e.Address)
                .HasMaxLength(100)
                .IsUnicode(false);
            entity.Property(e => e.Content)
                .HasMaxLength(100)
                .IsUnicode(false);
            entity.Property(e => e.Time).HasColumnType("datetime");
            entity.Property(e => e.Title)
                .HasMaxLength(50)
                .IsUnicode(false);

            entity.HasOne(d => d.UidNavigation).WithMany(p => p.Messages)
                .HasForeignKey(d => d.Uid)
                .HasConstraintName("FK__Message__Uid__09746778");
        });

        modelBuilder.Entity<Pder>(entity =>
        {
            entity.HasKey(e => e.Pbh).HasName("PK__pder__DD30202918DB989F");

            entity.ToTable("pder");

            entity.Property(e => e.Pbh)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("pbh");
            entity.Property(e => e.Dbh)
                .HasMaxLength(10)
                .IsUnicode(false)
                .HasColumnName("dbh");
            entity.Property(e => e.Dizhi)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasDefaultValueSql("(getdate())")
                .HasColumnName("dizhi");
            entity.Property(e => e.Pdata)
                .HasColumnType("datetime")
                .HasColumnName("pdata");
            entity.Property(e => e.Ptype).HasColumnName("ptype");
            entity.Property(e => e.Sdizhi)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("sdizhi");
            entity.Property(e => e.UserId).HasColumnName("userID");
            entity.Property(e => e.Wcdata)
                .HasColumnType("datetime")
                .HasColumnName("wcdata");
            entity.Property(e => e.Zhifu)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("zhifu");
            entity.Property(e => e.Zt).HasColumnName("zt");

            entity.HasOne(d => d.User).WithMany(p => p.Pders)
                .HasForeignKey(d => d.UserId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_pder_Users");
        });

        modelBuilder.Entity<Pderxq>(entity =>
        {
            entity.HasKey(e => e.Pxqid).HasName("PK__pderxq__0BCF80A4A7A73CBA");

            entity.ToTable("pderxq");

            entity.Property(e => e.Pxqid).HasColumnName("pxqid");
            entity.Property(e => e.GId).HasColumnName("gId");
            entity.Property(e => e.Pbh)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("pbh");
            entity.Property(e => e.Pl)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasColumnName("pl");
            entity.Property(e => e.Price).HasColumnName("price");
            entity.Property(e => e.Sfpl).HasColumnName("sfpl");
            entity.Property(e => e.Shu).HasColumnName("shu");

            entity.HasOne(d => d.GIdNavigation).WithMany(p => p.Pderxqs)
                .HasForeignKey(d => d.GId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_pderxq_Goods");

            entity.HasOne(d => d.PbhNavigation).WithMany(p => p.Pderxqs)
                .HasForeignKey(d => d.Pbh)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_pderxq_pder");
        });

        modelBuilder.Entity<Role>(entity =>
        {
            entity.Property(e => e.RoleId).HasColumnName("roleID");
            entity.Property(e => e.DeptId).HasColumnName("deptID");
            entity.Property(e => e.LastTime)
                .HasColumnType("smalldatetime")
                .HasColumnName("lastTime");
            entity.Property(e => e.Remark)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("remark");
            entity.Property(e => e.RoleName)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("roleName");
            entity.Property(e => e.Type).HasColumnName("type");

            entity.HasOne(d => d.Dept).WithMany(p => p.Roles)
                .HasForeignKey(d => d.DeptId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Roles_Department");
        });

        modelBuilder.Entity<User>(entity =>
        {
            entity.Property(e => e.UserId).HasColumnName("userID");
            entity.Property(e => e.Birthday).HasColumnName("birthday");
            entity.Property(e => e.ImgId).HasColumnName("imgID");
            entity.Property(e => e.LastTime)
                .HasColumnType("smalldatetime")
                .HasColumnName("lastTime");
            entity.Property(e => e.LoginName)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("loginName");
            entity.Property(e => e.LoginPwd)
                .HasMaxLength(32)
                .IsUnicode(false)
                .HasColumnName("loginPwd");
            entity.Property(e => e.Phone)
                .HasMaxLength(11)
                .IsUnicode(false)
                .IsFixedLength()
                .HasColumnName("phone");
            entity.Property(e => e.RoleId).HasColumnName("roleID");
            entity.Property(e => e.Sex)
                .HasMaxLength(2)
                .IsUnicode(false)
                .IsFixedLength()
                .HasColumnName("sex");
            entity.Property(e => e.Status).HasColumnName("status");
            entity.Property(e => e.UserName)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasColumnName("userName");

            entity.HasOne(d => d.Img).WithMany(p => p.Users)
                .HasForeignKey(d => d.ImgId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Users_Images");

            entity.HasOne(d => d.Role).WithMany(p => p.Users)
                .HasForeignKey(d => d.RoleId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Users_Roles");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
